package com.api.projectY.controller;

import com.api.common.core.controller.BaseController;
import com.api.common.core.domain.AjaxResult;
import com.api.core.domain.query.score.DatColScoreQuery;
import com.api.core.domain.query.score.ElementScoreQuery;
import com.api.core.domain.query.score.LineScoreQuery;
import com.api.core.domain.query.score.RobotSocreQuery;
import com.api.core.domain.vo.DevicesScoreVo;
import com.api.core.service.IDevicesScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评分
 */
@RestController
@RequestMapping("/score")
public class DeviceScoreController extends BaseController {
    @Autowired
    private IDevicesScoreService devicesScoreService;

    @PostMapping("list")
    public AjaxResult getDevicesScore(@RequestBody DevicesScoreVo devicesScoreVo
            , @RequestHeader("App-Language") String appLang) {
        devicesScoreVo.setAppLang(appLang);
//        List<DevicesScoreQuery> devicesScoreQueries = devicesScoreService.searchDevicesScore2(devicesScoreVo);
        List<LineScoreQuery> devicesScoreQueries = devicesScoreService.searchDevicesScore(devicesScoreVo);
//        devicesScoreQueries.stream().forEach(devicesScoreQuery -> {
//            try {
//                devicesScoreQuery..initLabelValue();
//            } catch (Exception e) {
//                throw new RuntimeException(e);
//            }
//        });
        for (LineScoreQuery lineScoreQuery : devicesScoreQueries) {
//            List<RobotSocreQuery> lChildren = lineScoreQuery.getChildren();
            for (RobotSocreQuery robotSocreQuery : lineScoreQuery.getChildren()) {
                for (ElementScoreQuery elementScoreQuery : robotSocreQuery.getChildren()) {
                    for (DatColScoreQuery datColScoreQuery : elementScoreQuery.getChildren()) {
//                        try {
//                            datColScoreQuery.initLabelValue();
//                        } catch (Exception e) {
//                            throw new RuntimeException(e);
//                        }
                    }
                }
            }
        }
        ;
        return AjaxResult.success(devicesScoreQueries);
    }

    @PostMapping("history")
    public AjaxResult evlAvgScoreOfSlope(@RequestBody DevicesScoreVo devicesScoreVo
            , @RequestHeader("App-Language") String appLang) {
        devicesScoreVo.setAppLang(appLang);
        return AjaxResult.success(devicesScoreService.evlAvgScoreOfSlope(devicesScoreVo));
    }

    @PostMapping("evaluate")
    public AjaxResult actionEstimat(@RequestBody DevicesScoreVo devicesScoreVo) {
        return AjaxResult.success(devicesScoreService.actionEstimat(devicesScoreVo));
    }
}
